package com.gcd.api;


import com.gcd.service.MemberService;
import com.gcd.utils.JsonResult;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/member")
public class MemberApi {
    private MemberService memberService;

    @Autowired
    public void setMemberService(MemberService memberService) {
        this.memberService = memberService;
    }
    @GetMapping
    public ResponseEntity<JsonResult<?>> findById(@RequestAttribute("userId") Integer id) {
        return ResponseEntity.ok(JsonResult.success(memberService.findById(id)));
    }

//    会员注册
    @PutMapping("/vipRegister")
    public ResponseEntity<JsonResult<?>> vipRegister(@RequestAttribute("userId") Integer memberId) {
        boolean result= memberService.registerVip(memberId);
        if( result) {
            return ResponseEntity.ok(JsonResult.success(null,"会员注册成功"));
        } else {
            return ResponseEntity.ok(JsonResult.fail("会员注册失败"));
        }
    }
}
